<!--
 * @Autor: 黄旗
 * @Date: 2020-06-02 17:47:26
-->
<template>
  <div id="app">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
  </div>
</template>
<script>
import { on, off } from "view-design/src/utils/dom";
import { setMatchMedia } from "view-design/src/utils/assist";

import { mapMutations } from "vuex";

setMatchMedia();

export default {
  name: "app",
  methods: {
    ...mapMutations("admin/layout", ["setDevice"]),
    handleWindowResize() {
      this.handleMatchMedia();
    },
    handleMatchMedia() {
      const matchMedia = window.matchMedia;

      if (matchMedia("(max-width: 600px)").matches) {
        this.setDevice("Mobile");
      } else if (matchMedia("(max-width: 992px)").matches) {
        this.setDevice("Tablet");
      } else {
        this.setDevice("Desktop");
      }
    },
  },
  mounted() {
    let menus = JSON.parse(localStorage.getItem("menus"));
    this.$store.commit("admin/menu/setHeader", menus.header);
    on(window, "resize", this.handleWindowResize);
    this.handleMatchMedia();
  },
  beforeDestroy() {
    off(window, "resize", this.handleWindowResize);
  },
};
</script>
<style>
.ivu-modal-no-mask {
  pointer-events: auto !important;
  background-color: rgba(7, 17, 27, 0.5);
  z-index: 1001 !important;
}
</style>
